home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / perlcl16.lha / perlclass1.6 / perlclass.doc < prev    next >
Text File  |  1992-11-10  |  11KB  |  315 lines

  1. class PerlList<T>    - A list of any type specified by T
  2.  
  3.     T& operator[n]    - returns a reference to the element at index
  4.               'n' (0 based). Generates an ASSERT error
  5.               if n < 0, can be used as an lvalue. Using
  6.               an index greater than the current size of the
  7.               list will cause the list to grow upto that
  8.               index. The values inbetween will be undefined
  9.               if <T> is a built-in type.
  10.  
  11.     operator void*()    - returns NULL if the list is empty,
  12.               can be used like: if(list) // not empty
  13.  
  14.     int isempty()    - returns TRUE if the list is empty, as an
  15.               alternative for the previous technique
  16.  
  17.     void reset()    - clears all elements in the list, but doesn't
  18.               actually free up the storage until it is
  19.               destroyed
  20.  
  21.     int scalar()    - returns the number of elements in the list
  22.  
  23.     T pop()        - removes and returns the last element on the
  24.               list. If the list is empty the value returned
  25.               is usually undefined
  26.  
  27.     void push(T x)    - puts the single value 'x' at the end of the
  28.               list
  29.  
  30.  
  31.     void push(PerlList<T> l)
  32.              - puts all the elements in the list 'l' at the
  33.               end of the list.
  34.  
  35.     T shift()        - removes and returns the first element
  36.               in the list
  37.  
  38.     int unshift(T x)    - puts the single value 'x' at the start
  39.               of the list
  40.  
  41.     int unshift(PerlList<T> l)
  42.             - puts all the elements in the list 'l'
  43.               at the start of the list
  44.  
  45.     PerlList<T> reverse()
  46.             - returns a list that is in the reverse
  47.               order
  48.  
  49.     PerlList<T> splice(offset, len, PerlList<T> l)
  50.             - removes 'len' elements from 'offset' (0 based)
  51.               and inserts all the elements in the list 'l'
  52.               at the same position
  53.                 
  54.     PerlList<T> splice(offset, len)
  55.             - removes 'len' elements from 'offset' (0 based)
  56.  
  57.     PerlList<T> splice(offset)
  58.             - removes all the elements from 'offset'
  59.               (0 based)
  60.  
  61.     PerlList<T> sort()    - returns a list that has been sorted according
  62.               to the rules that T::operator<() returns
  63.               for the type T.
  64.  
  65. class PerlStringList    - everything PerlList does and ...
  66.  
  67.     int split(str [,pat] [,limit])
  68.             - appends the results of splitting the string
  69.               'str' to the list. If 'pat' is specified then
  70.               any string that matches the RE 'pat' is
  71.               considered a separator to split on, the
  72.               default is white-space. If 'limit' is specified
  73.               then no more than that number of elements is
  74.               generated. If 'limit' is not specified, then empty
  75.               entries are stripped from the end of the list.
  76.               If the RE includes subexpressions then they
  77.               are inserted into the list as well.
  78.               If 'pat' is equal to the string "' '" then
  79.               a special case is done which matches awks
  80.               handling of whitespace. If 'pat' is an empty
  81.               string "", then all characters are split into
  82.               the list
  83.  
  84.     PerlString join([pat])
  85.             - Returns the string that is the result of
  86.               combining all the elements in the list, and
  87.               separating them by 'pat'. If 'pat' is omitted
  88.               then the elements are separated by a space
  89.  
  90.     int m(const char *exp, targ [,opts)
  91.             - Appends to the list all the subexpression
  92.               matches that occured when applying the regular
  93.               expression 'exp' to the string 'targ'.
  94.               The number of matches is returned. The first
  95.               element generated is the entire matched string
  96.               opts: (a const char * with default "")
  97.                   i - Forces case insensitive match
  98.     
  99.     PerlStringList grep(const char *exp [,opts])
  100.             - returns a list of all the elements that
  101.               matched the regular expression 'exp'.
  102.               opts: (a const char * with default "")
  103.                   i - Forces the search to be case insensitive
  104.  
  105. class PerlString    - A standard c null-terminated string may be
  106.               used anywhere that a perl string can be used
  107.               and vice-versa.
  108.             - Individual characters may be read with
  109.               the '[]' operator (unlike perl).
  110.  
  111.     int length()    - returns the length of the string
  112.  
  113.     char chop()        - removes and returns the last character in the
  114.               string
  115.  
  116.     int index(PerlString str [, offset])
  117.             - returns the offset in the string that matches
  118.               the string 'str', starting at position
  119.               'offset' if specified, otherwise searches the
  120.               entire string.
  121.               Returns -1 if no match is found
  122.  
  123.     int rindex(PerlString str [, offset])
  124.             - returns the offset in the string that matches
  125.               the string 'str', starting at the end of the
  126.               string - 'offset' if specified, otherwise
  127.               searches the entire string.
  128.               Returns -1 if no match is found
  129.  
  130.     substring substr(offset [, len])
  131.             - returns the substring within the string that
  132.               starts at 'offset' and is 'len' characters, if
  133.               'len' is omitted the rest of the string is
  134.               returned.
  135.               This may be used as an lvalue, in which case
  136.               the characters are removed, and the RHS of the
  137.               expression in inserted at the same postion.
  138.  
  139.     PerlStringList split([,pat] [,limit])
  140.             - same as PerlStringList::split() but returns
  141.               a list of splits
  142.  
  143.     operator<        - These operators do what you would expect
  144.     operator>
  145.     operator<=
  146.     operator>=
  147.     operator==
  148.     operator!=
  149.  
  150.     operator+        - returns the result of contenating two or more
  151.               strings
  152.  
  153.     operator+=        - replaces the LHS of the expression with the
  154.               concatenation of the LHS with the RHS
  155.  
  156.     int m(const char *exp [,opts])
  157.             - returns 0 if the regular expression 'exp'
  158.               fails to match the string. Returns 1 if a
  159.               match was made
  160.               opts: (a const char * with default "")
  161.                   i - Forces case insensitive match
  162.     int m(const Regexp& exp)
  163.             - Same as above but takes a precompiled
  164.               regular expression.
  165.  
  166.     int m(const char *exp, PerlStringList& l [,opts])
  167.             - Loads the list 'l' with all subexpression
  168.               matches of the regular expression 'exp' with
  169.               the string. Returns 0 if no matches were made.
  170.               Returns the number of matches if any
  171.               opts: (a const char * with default "")
  172.                   i - Forces case insensitive match
  173.  
  174.     int m(const Regexp& exp, PerlStringList& l)
  175.             - Same as above but takes a precompiled
  176.               regular expression.
  177.  
  178.     int tr(search, repl [,opts])
  179.             - replaces all occurrences of characters in 'search'
  180.               with the equivalent character in 'repl'. If 'repl'
  181.               is empty then just counts the characters.
  182.               opts: (a const char *) default is ""
  183.                  c - complements the 'search' pattern. Replaces
  184.                  all characters that are not in 'search', with
  185.                  the last character specified in 'repl'.
  186.                  d - deletes characters in 'search' that don't have an
  187.                  equivalent 'repl'
  188.                 cd - deletes characters not in 'search' 
  189.                  s - compresses sequences of translated characters
  190.                  in resulting string
  191.  
  192.     int s(exp, repl [,opts])
  193.             - substitute the first substring matched by
  194.               'exp' with the string 'repl'. $& in 'repl'
  195.               will be replaced by the entire matching
  196.               string, $1 - $9 will be replaced by the
  197.               respective subexpression match. \$ or \\
  198.               will insert a $ or \ respectively.
  199.               opts: (a const char *) default is ""
  200.                  g - causes all occurrences of 'exp' in
  201.                  the string to be replaced by 'repl'
  202.                  i - Forces case insensitive matching                
  203.  
  204. class Assoc<T>        - an associative array whose key is a PerlString
  205.               and the value is any type T
  206.  
  207.     Assoc(PerlString defkey, T defvalue)
  208.             - Constructor for an associative array, 'defkey'
  209.               becomes the default key, and 'defvalue' is the
  210.               default value. The default value is used to
  211.               create a new Association if a key is specified
  212.               that doesn't yet exist.
  213.  
  214.     T& operator(PerlString str)
  215.             - returns a reference to the value that is
  216.               associated with the key 'str'. This may be
  217.               used as an lvalue, and is in the only way to
  218.               make an association. If the key didn't exist
  219.               it will be entered with the default value, if
  220.               it was specified in the constructor, and a
  221.               reference to that is returned. If no default
  222.               was specified, then the value will be
  223.               undefined
  224.  
  225.     Binar& operator[n]    - Returns the (key, value) pair found at index
  226.               'n' of the associative array
  227.  
  228.     PerlStringList keys()
  229.             - Returns a list of all the keys in the
  230.               associative array.
  231.  
  232.     PerlList<T> values()
  233.             - Returns a list of all the values in the
  234.               associative array.
  235.  
  236.     int isin(PerlString key)
  237.             - Returns 1 if the string 'key' is a valid key
  238.               in the associative array. Returns 0 otherwise.
  239.  
  240.     T adelete(PerlString key)
  241.             - deletes the entry whose key matches the string
  242.               'key'. The value of the deleted entry is
  243.               returned. Nothing happens if the key is not
  244.               found.
  245.  
  246. Miscellaneous
  247. =============
  248. class Range        - stores the range used in Regexp
  249.  
  250.     Range(s, e)        - creates a range whose start is at position
  251.               's' and the last character in the range is at
  252.               position 'e'. (inclusive range)
  253.     
  254.     int start()        - returns the start of the range
  255.  
  256.     int end()        - returns the end of the range (the position
  257.               of the last character in the range).
  258.  
  259.     int length()    - returns the length of the range.
  260.  
  261.  
  262. class Regexp        - Henry Spencers regular expression package
  263.               oo-ized
  264.  
  265.     Regexp(exp [,opts])    - Compiles a regular expression that can be
  266.               passed to one of the m() functions.
  267.               opts: (an int with default 0)
  268.                   Regexp::nocase - Forces case insensitive
  269.                            match
  270.  
  271.     int match(targ)    - returns 1 if the compield RE matches 'targ'
  272.               returns 0 if not
  273.     
  274.     int groups()    - returns 1 + the number of subexpression
  275.               matches found in the last match(). If the
  276.               previous match() succeeded then the whole
  277.               match is included in the count (hence +1)
  278.     
  279.     Range getgroup(n)    - returns the range of the 'n'th subgroup.
  280.               'n' = 0 is the range of the entire match
  281.  
  282. PerlStringList m(exp, targ [,opts])
  283.             - returns a list of all the subexpression
  284.               matches that occured when applying the
  285.               regular expression 'exp' to the string
  286.               'targ'. element 0 of the list is the first
  287.               subexpression, element 1 the next, etc.
  288.               opts: (a const char * with default "")
  289.                   i - Forces case insensitive match
  290.  
  291. xin >> aperlstring
  292.             - Text from the stream xin is loaded into
  293.               aperlstring, the text is expected to be
  294.               terminated by '\n', which is removed from
  295.               the stream, but not put into aperlstring.
  296.               aperlsring is cleared first.
  297.  
  298. xin >> aperlstringlist
  299.             - Each Text line, as defined above, is loaded
  300.               into an element of aperlstringlist, which
  301.               is reset first.
  302.  
  303. To pre-compile a regular expression use Regexp(const char *, iflg).
  304. eg
  305. Regexp rexp("...([a-z*)$");
  306. //Regexp rexp("...([a-z*)$", Regexp::nocase); // for case insensitive
  307. PerlString s;
  308.  
  309. for(int i=0;i<large_number;i++){
  310.     ... load s with string ...
  311.     if(s.m(rexp)) ... do something when matched
  312. }
  313.  
  314.  
  315.